<?php
//$_GET['id']
//$_GET['confirm']有值则表示需要确认
//
//直接子节点会移到该节点的父节点
//id节点需要delete权限，parent节点需要add权限

	include 'include/function.php';
	
	if(!isset($_user_id))redirect_error(_d('err_need_login'));
	
	$deletenode_id=-1;
	if(isset($_GET['id']))$deletenode_id=get_to_mysql($_GET['id']);
	if($deletenode_id==-1)redirect_error('Root node cant be deleted.');
	//存在性检测
	$query="select title,parent from node where id=$deletenode_id ";
	$ret=oj_query($query);
	$row=mysql_fetch_row($ret);
	if(!isset($row[0]))redirect_error(_d('err_no_node'));
	//权限检测（该节点的delete权限和父节点的add权限）
	$deletenode_title	=$row[0];
	$deletenode_parent	=$row[1];
	permission_check_delete($_user_id,$deletenode_id);
	permission_check_add($_user_id,$deletenode_parent);
	//confirm
	if(!isset($_GET['confirm'])) {
		update_child_count($deletenode_id,-1);
		$query="update node set parent=$deletenode_parent, child_update_time=now() where parent=$deletenode_id ";
		$ret=oj_query($query);
		$query="delete from node where id=$deletenode_id ";
		$ret=oj_query($query);
		redirect('shownode.php?id=' . $deletenode_parent);
	}
	//待确认
	include 'include/header.php';
	echo "<title>$site_title - Delete Node $deletenode_title</title>";
	echo '<center style="font-size:2em;padding-bottom:1em;">';
		echo "Are you sure to delete the node-$deletenode_id ($deletenode_title) ?<br>";
		echo 'Children node will be moved to parent node.<br>';
	echo '</center>';
	echo "<center><a href='deletenode.php?id=$deletenode_id'>Yes</a>&nbsp;&nbsp;<a href='shownode.php?id=$deletenode_id'>Cancel</a></center>";
	
	include 'include/footer.php';
		
?>

